//
//  LoginView.swift
//  fsapp
//
//  Created by zguang on 17/7/28.
//  Copyright © 2017年 huangshengjie. All rights reserved.
//

import Foundation
import  UIKit

class loginView{
    
    
    var text1 = ""
    var  text2 = ""
    
    init(type:String) {
        
        switch type{
            
        case "login":
        self.text1 = "+86"
        self.text2 = "密码"
//loginNow.setTitle("下一步", for: .normal)
        BackView.addSubview(phoneText)
        BackView.addSubview(passwordText)
        BackView.addSubview(registerButton)
        BackView.addSubview(forgetButton);
         loginNow.setTitle("立即登录", for: .normal)
        BackView.addSubview(loginNow)
        BackView.addSubview(visibleButton);
        //BackView.addSubview(codeText)
        //BackView.addSubview(upImageButton)
        //BackView.addSubview(headImageView)
        //BackView.addSubview(confirmPasswordText)
        //BackView.addSubview(getcodeButton)
        case "regist1":
            self.text1 = "+86"
            self.text2 = "验证码"
            BackView.addSubview(phoneText)
            BackView.addSubview(codeText)
            loginNow.setTitle("下一步", for: .normal)
            BackView.addSubview(loginNow)
            BackView.addSubview(getcodeButton)
            BackView.addSubview(agreement)
            BackView.addSubview(agreeButton)
            BackView.addSubview(linkAgreement)
        case "regist2":
             self.text1 = "密码"
             self.text2 = "确认密码"
             loginNow.setTitle("完成", for: .normal)
             self.loginNow.frame =  CGRect(x:getWidth(width: 46),y:getHeight(609+150),width:getWidth(width: 661),height:getHeight(90))
             BackView.addSubview(upImageButton)
             BackView.addSubview(headImageView)
             BackView.addSubview(loginNow)
             BackView.addSubview(accountLabel)
             BackView.addSubview(accountText)
             
             BackView.addSubview(userText)//输入密码
             BackView.addSubview(confirmPasswordText)
             BackView.addSubview(visibleButton)
            BackView.addSubview(upvisibleButton)
        default : break
        }
    }


    
    lazy var  BackView:UIView = {
        let backView = UIView(frame:CGRect(x:0,y:0,width:SCREEN_WIDTH,height:SCREEN_HEIGHT))
        let imageLogo = UIImageView(frame:CGRect(x:(SCREEN_WIDTH/CGFloat(2)-(width(187/2))),y:height(90),width:width(187),height:height(187)))
    
        imageLogo.image = #imageLiteral(resourceName: "logo")
        let label1 = UILabel(frame:CGRect(x:width(38),y:height(320+10),width:width(26*3),height:height(26)))
        label1.textColor = UIColor.black
        label1.text = self.text1
        label1.font = UIFont.systemFont(ofSize: height(26))
        label1.sizeToFit()
        let label2 = UILabel(frame:CGRect(x:width(38),y:height(320+89+10),width:width(26*5),height:height(26)))
        label2.font = UIFont.systemFont(ofSize: height(26))
        label2.textAlignment = .left
        
        label2.text = self.text2
        label2.textColor = UIColor.black
        let line1 = UIView(frame:CGRect(x:width(38),y:height(320+26+29),width:width(655),height:height(2)))
        line1.backgroundColor = lineColor
        
        let line2 = UIView(frame:CGRect(x:width(38),y:height(320+90+29+20),width:width(655),height:height(2)))
        line2.backgroundColor = lineColor
        
        
        let text: String = self.text1
        let label = UILabel(frame:CGRect(x:width(38),y:height(320+10),width:width(26*3),height:height(26)))        // label.numberOfLines = 0
        // label.backgroundColor = UIColor.green
        label.font = UIFont.systemFont(ofSize: height(26))
        label.lineBreakMode = .byCharWrapping
        //设置字间距
        
        if self.text1 == "密码" {
        let dic: [AnyHashable: Any] = [NSKernAttributeName: 2*width(26)]
        var attributedString = NSMutableAttributedString(string: text, attributes: dic as? [String : Any] ?? [String : Any]())
        var paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 30
        //行间距
        attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: (text.characters.count ?? 0)))
        label.attributedText = attributedString
        label.sizeToFit()
        }else{
        
            
            let dic: [AnyHashable: Any] = [NSKernAttributeName: width(2)]
            var attributedString = NSMutableAttributedString(string: text, attributes: dic as? [String : Any] ?? [String : Any]())
            var paragraphStyle = NSMutableParagraphStyle()
            paragraphStyle.lineSpacing = 30
            //行间距
            attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: (text.characters.count ?? 0)))
            label.attributedText = attributedString
            label.sizeToFit()
        
        
        }
        
        
        
        
        backView.addSubview(line1)
        backView.addSubview(line2)
        backView.addSubview(imageLogo)
        backView.addSubview(label)
        backView.addSubview(label2)
        
    return backView
    }()
    
    lazy var accountLabel:UILabel = {
      
        
        let text: String = "用户名"
        let label = UILabel(frame: CGRect(x:width(38),y:height(320+86+86),width:width(26*7),height:height(26)))
       // label.numberOfLines = 0
       // label.backgroundColor = UIColor.green
        label.font = UIFont.systemFont(ofSize: height(26))
        label.lineBreakMode = .byCharWrapping
        //设置字间距
        let dic: [AnyHashable: Any] = [NSKernAttributeName: (1/3)*width(37)]
        var attributedString = NSMutableAttributedString(string: text, attributes: dic as? [String : Any] ?? [String : Any]())
        var paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 30
        //行间距
        attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: (text.characters.count ?? 0)))
        label.attributedText = attributedString
        label.sizeToFit()

        let label2 = UILabel(frame:CGRect(x:width(38),y:height(320+86+86),width:width(26*5),height:height(26)))
        label2.attributedText = attributedString
        label2.font = UIFont.systemFont(ofSize: height(26))
        label2.textAlignment = .left
        


        label2.textColor = UIColor.black
        let line1 = UIView(frame:CGRect(x:width(0),y:height(29+11),width:width(655),height:height(2)))
        label.addSubview(line1)
        line1.backgroundColor = lineColor
        return label
        
    }()
    
    lazy var  phoneText:UITextField = {
       let text = UITextField(frame:CGRect(x:width(118),y:height(320),width:width(555),height:height(56)))
        text.placeholder = "输入手机号"
        text.font = UIFont.systemFont(ofSize: height(32))
        text.keyboardType = .numberPad
        return text
    }()
    
    lazy var  userText:UITextField = {
        let text = UITextField(frame:CGRect(x:width(160),y:height(320),width:width(555),height:height(56)))
        text.font = UIFont.systemFont(ofSize: height(32))
        text.isSecureTextEntry = true
        text.placeholder = "  请输入密码"
        return text
        
    }()
    
    
    lazy var  accountText:UITextField = {
        let text = UITextField(frame:CGRect(x:width(160),y:height(320+83+83),width:width(555),height:height(56)))
        text.font = UIFont.systemFont(ofSize: height(32))
       // text.isSecureTextEntry = true
        text.placeholder = "  输入昵称"
        return text
        
    }()
    
    
    lazy var  passwordText:UITextField = {
        let text = UITextField(frame:CGRect(x:width(118),y:height(320+83),width:width(555),height:height(56)))
        text.placeholder = "输入密码"
        text.isSecureTextEntry = true
        text.font = UIFont.systemFont(ofSize: height(32))
        return text
        
    }()
    
    lazy var  confirmPasswordText:UITextField = {
        let text = UITextField(frame:CGRect(x:width(160),y:height(320+83),width:width(555),height:height(56)))
        text.isSecureTextEntry = true
        text.font = UIFont.systemFont(ofSize: height(32))
        text.placeholder = "  确认密码"
        return text
        
    }()
    
    lazy var  codeText:UITextField = {
        let text = UITextField(frame:CGRect(x:width(118),y:height(320+83),width:width(555),height:height(56)))
        text.placeholder = "请输入验证码"
        text.keyboardType = .numberPad
        text.font = UIFont.systemFont(ofSize: height(32))
        return text
    }()
  
    lazy var headImageView:UILabel = {
       let image = UILabel(frame:CGRect(x:width(38),y:height(320+89+10+89+89),width:width(145),height:height(45)))
        image.font = UIFont.systemFont(ofSize: height(26))
        image.text = "上传头像"
        
       // image.image = #imageLiteral(resourceName: "FireShot ")
        return image
    }()
    lazy var upImageButton:UIButton = {
        let up = UIButton(frame:CGRect(x:width(175),y:height(320+89+10+89+89),width:width(100),height:height(100)))
             // up.setTitle("点击上传头像", for: .normal)
        up.setImage(#imageLiteral(resourceName: "头像"), for:  .normal)
        //up.layer.borderWidth = 1
        up.layer.cornerRadius = height(50)
        up.titleLabel?.adjustsFontSizeToFitWidth = true
        up.layer.masksToBounds = true
        up.setTitleColor(UIColor.black, for: .normal)
        return up
    }()
    lazy var getcodeButton:UIButton = {
        let up = UIButton(frame:CGRect(x:width(504),y:height(380),width:width(204),height:height(74)))
        up.setTitle("发送验证码", for: .normal)
        up.titleLabel?.adjustsFontSizeToFitWidth = true
        //up.layer.borderWidth = 1
        up.layer.cornerRadius = 6
        up.backgroundColor = naviColor
        up.layer.masksToBounds = true
        up.setTitleColor(UIColor.white, for: .normal)
        return up
    
    }()
    
    lazy var registerButton:UIButton = {
     let button = UIButton(frame:CGRect(x:width(38),y: height(320+90+29+40),width:width(56),height:height(26)))
       // label1.text = self.text1
       // label1.font = UIFont.systemFont(ofSize: height(26))
        button.setTitle("注册",for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: height(26))
        button.setTitleColor(naviColor,for:.normal)
     return button
    }()
    
    lazy var forgetButton:UIButton = {
        let button = UIButton(frame:CGRect(x:SCREEN_WIDTH - width(38+120),y:height(320+90+29+40),width:width(120),height:height(26)))
        // label1.text = self.text1
        // label1.font = UIFont.systemFont(ofSize: height(26))
        button.titleLabel?.font = UIFont.systemFont(ofSize: height(26))
        //button.sizeToFit()
        button.setTitle("忘记密码",for: .normal)

        button.setTitleColor(naviColor,for:.normal)
        return button
    }()
    
    
    lazy var loginNow:UIButton  = {
        let button  = UIButton(frame: CGRect(x:getWidth(width: 46),y:getHeight(312*2),width:getWidth(width: 661),height:getHeight(90)))
        button.layer.cornerRadius = 7
        button.setTitle("保存", for: .normal)
        button.backgroundColor = naviColor
        return button
    }()
    
    lazy var visibleButton :UIButton = {
        let button  = UIButton(frame:CGRect(x:SCREEN_WIDTH - width(38+72),y:height(320+89),width:width(72*2/3),height:height(50*2/3)))
        button.setImage(#imageLiteral(resourceName: "显示密码"), for: .normal)
        button.setImage(#imageLiteral(resourceName: "隐藏密码"), for: .selected)
        //button.layer.cornerRadius = 7
       // button.setTitle("立即登录", for: .normal)
        //button.backgroundColor = naviColor
        return button
    
    
    }()
    
    
    lazy var agreement:UILabel = {
        let agree = UILabel(frame: CGRect(x:getWidth(width: 46),y:getHeight(502),width:getWidth(width: 674),height:getHeight(30)))
        agree.text = "      我已阅读并同意"
        agree.font = UIFont.systemFont(ofSize: getHeight(26))
        agree.textColor = UIColor.black
        
        return agree
    }()
    
    lazy var agreeButton:UIButton = {
        
        let button = UIButton(frame: CGRect(x:getWidth(width: 46),y:getHeight(502),width:getWidth(width: 30),height:getHeight(30)))
        button.setImage(#imageLiteral(resourceName: "勾选"), for: .selected)
        button.setImage(#imageLiteral(resourceName: "未选中"), for: .normal)
        button.isSelected = true
        return button
    }()

    lazy var linkAgreement:UIButton = {
        //        let label = UIButton(frame:
        //
        let label = UIButton(frame:CGRect(x:getWidth(width: 380),y:getHeight(502),width:getWidth(width: 110),height:getHeight( 30)))
        label.setTitleColor(naviColor, for: .normal)
        label.setTitle("服务条款", for: .normal)
        label.titleLabel?.font = UIFont.systemFont(ofSize: getHeight(26))
        
        return label
    }()
  
    
    lazy var upvisibleButton :UIButton = {
        let button  = UIButton(frame:CGRect(x:SCREEN_WIDTH - width(38+72),y:height(330),width:width(72*2/3),height:height(50*2/3)))
        button.setImage(#imageLiteral(resourceName: "显示密码"), for: .normal)
        button.setImage(#imageLiteral(resourceName: "隐藏密码"), for: .selected)
        //button.layer.cornerRadius = 7
        // button.setTitle("立即登录", for: .normal)
        //button.backgroundColor = naviColor
        return button
        
        
    }()
    
    //lazy var agreement:UILabel = {}()


}
